const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const sourceValidate = require('@/middlewares/validateMiddlewares/sourceValidate')
const sourceController = require('@/controller/sourceController')
const sourceLog = require('@/middlewares/logMiddlewares/sourceLog')
const { verifyAuth } = require('@/middlewares/authMiddlewares/verifyAuth')
const router = new Router()

/**
 * 用户获取文件列表
 */
router.get(
  '/list',
  verifyToken(),
  verifyAuth(['source.search']),
  sourceValidate.listSourceValidate,
  sourceController.listSource
)

/**
 * 用户获取外链分享的文件列表
 */
router.get(
  '/linkShare/list',
  // verifyToken(),
  // verifyAuth(['source.search']),
  sourceValidate.listLinkShareSourceValidate,
  sourceController.listSource
)

/**
 * 用户根据sourceId获取文件详情
 */

router.get(
  '/id/list',
  verifyToken(),
  verifyAuth(['source.view']),
  sourceValidate.listSourceByIdValidate,
  sourceController.listSourceById
)

/**
 * 用户根据sourceId获取文件日志
 */

router.get(
  '/log/id',
  verifyToken(),
  verifyAuth(['source.view']),
  sourceValidate.listSourceLogByIdValidate,
  sourceController.listSourceLogById
)

/**
 * 根据不同的分类获取用户空间下的所有类型的文件
 */
router.get(
  '/fileType/list',
  verifyToken(),
  verifyAuth(['source.search']),
  sourceValidate.listFileTypeSourceValidate,
  sourceController.listFileTypeSource
)

/**
 * 查询回收站里面的文件
 */
router.get(
  '/bin/list',
  verifyToken(),
  verifyAuth(['source.search']),
  sourceValidate.listBinSourceValidate,
  sourceController.listBinSource
)

/**
 * 用户创建文件夹
 */
router.post(
  '/createDir',
  verifyToken(),
  verifyAuth(['source.add']),
  sourceValidate.createDirValidate,
  sourceLog.updateSourceLog,
  sourceController.createDir
)

/**
 * 用户创建普通文件接口
 */
router.post(
  '/createFile',
  verifyToken(),
  verifyAuth(['source.add']),
  sourceValidate.createFileValidate,
  sourceLog.updateSourceLog,
  sourceController.createFile
)

/**
 * 用户修改文件名称
 */
router.put(
  '/rename',
  verifyToken(),
  verifyAuth(['source.edit']),
  sourceValidate.renameValidate,
  sourceLog.updateSourceLog,
  sourceController.rename
)

/**
 * 用户移动文件接口
 */
router.put(
  '/move',
  verifyToken(),
  verifyAuth(['source.move']),
  sourceValidate.moveFileValidate,
  sourceLog.updateSourceLog,
  sourceController.moveFile
)

/**
 * 用户复制文件接口
 */
router.put(
  '/copy',
  verifyToken(),
  verifyAuth(['source.move']),
  sourceValidate.moveFileValidate,
  sourceLog.updateSourceLog,
  sourceController.copyFile
)

/**
 * 用户彻底删除文件接口
 */
router.delete(
  '/delete',
  verifyToken(),
  verifyAuth(['source.remove']),
  sourceValidate.delFileValidate,
  sourceLog.updateSourceLog,
  sourceController.delFile
)

/**
 * 用户将文件放入回收站接口
 */
router.delete(
  '/bin',
  verifyToken(),
  verifyAuth(['source.remove']),
  sourceValidate.binFileValidate,
  sourceLog.updateSourceLog,
  sourceController.binFile
)

/**
 * 用户还原文件接口
 */
router.delete(
  '/recycle',
  verifyToken(),
  verifyAuth(['source.remove']),
  sourceValidate.recFileValidate,
  sourceLog.updateSourceLog,
  sourceController.recFile
)

/**
 * 用户打包下载文件接口，对应文件夹的情况
 */
router.post(
  '/zipDownload',
  verifyToken(),
  verifyAuth(['source.download']),
  sourceValidate.zipDownloadValidate,
  // sourceLog.updateSourceLog,
  sourceController.zipDownload
)

/**
 * 用户单文件下载接口，对于全是文件的情况
 */
router.post(
  '/fileDownload',
  verifyToken(),
  verifyAuth(['source.download']),
  sourceValidate.fileDownloadValidate,
  // sourceLog.updateSourceLog,
  sourceController.fileDownload
)

/**
 * 用户文件授权接口
 */
router.post(
  '/auth',
  verifyToken(),
  sourceValidate.authSourceValidate,
  sourceController.authSource
)

/**
 * 用户获取对文件列表的权限数组
 */

router.post(
  '/sourceAuth',
  verifyToken(),
  sourceValidate.getSourceAuthValidate,
  sourceController.getSourceAuth
)

/**
 * 用户获取对文件的角色
 */
router.post(
  '/sourceRole',
  verifyToken(),
  sourceValidate.getSourceRoleValidate,
  sourceController.getSourceRole
)

module.exports = router
